/**
 * Company : Thai Informatic System Co., Ltd.
 * Created By : Dr.Tree
 * Created On : Sep 24, 2012  12:45:50 PM 
 * e-Mail : chatree@tis.co.th
 * Mobile Phone : (+66) 087-921-5115
 * Package Name : apps.business.process.construction.budget
 * File Name : BudgetActivityProcessing.java
 * TODO
 */
package apps.business.process.construction.budget;

import java.util.List;

import jpa.entitys.synchro.staging.PsProjPlanBudget;

import org.apache.log4j.Logger;

import promis.utility.CommonService;
import sap.business.ps.outbound.SyncBudgetActivityService;

import apps.business.process.SyncProcessorCommons;
import apps.promis.out.common.PsProjPlanBudgetAction;


/**
 * @author chatree
 *
 */
public class BudgetActivityHighRiseProcessing  extends SyncProcessorCommons{
	
	private static final Logger log = Logger.getLogger(BudgetActivityHighRiseProcessing.class);
	
	public void Processing(String company, String project, String documentNo, String status) throws Exception {
		System.out.println("Start BudgetActivityHighRise Processing  [company="+ company +" || project="+ project +" || documentNo="+ documentNo +" || status="+ status + "]");
		try{
			UPD_PROMISUseTime(true, false, null);
			List<PsProjPlanBudget>  lst = new PsProjPlanBudgetAction().CreateToStaging(company, project, documentNo, status);			
			System.out.println("Create to Staging Size=" + CommonService.getSize(lst));
			UPD_PROMISUseTime(false, true, null); 
			 
			 if(CommonService.getSize(lst) > 0){
				 UPD_SENDUseTime(true, false, lst.get(0).getInstanceNo());
				 new SyncBudgetActivityService().SendingToSAP(lst);
				 UPD_SENDUseTime(false, true, lst.get(0).getInstanceNo());				 
			 }
			 System.out.println("Send to SAP  [company="+ company +" || project="+ project +" || documentNo="+ documentNo +" || status="+ status + "] Size="+CommonService.getSize(lst));
			 
		}catch(Exception e){
			log.error(e.getMessage());
			System.err.println(e.getMessage());
		}finally{
			System.out.println("End BudgetActivityHighRise Processing  [company="+ company +" || project="+ project +" || documentNo="+ documentNo +" || status="+ status + "]");			
		}
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		try{
			
			String company = "SP";
			String project = "SP-AP";
			String documentNo = "BG-1207-0001-0";
			String status = "A";
			
			new BudgetActivityHighRiseProcessing().Processing(company, project, documentNo, status);
			
		}catch(Exception e){
			log.error(e.getMessage());
			System.err.println(e.getMessage());
		}
		
	}

}
